﻿using Microsoft.AspNetCore.Mvc;
using System;
using System.Threading.Tasks;
using Volo.Abp;
using Volo.Abp.Application.Dtos;
using Volo.Abp.Identity;

namespace Acme.BookStore2.Controllers
{
    [RemoteService(Name = IdentityRemoteServiceConsts.RemoteServiceName)]
    [Area("identity")]
    [ControllerName("OrganizationUnit")]
    [Route("api/identity/organization-units")]
    public class OrganizationUnitController : BookStore2Controller
    {
        private readonly IOrganizationUnitAppService _organizationUnitAppService;

        public OrganizationUnitController(IOrganizationUnitAppService organizationUnitAppService)
        {
            _organizationUnitAppService = organizationUnitAppService;
        }

        [HttpPost]
        public Task<OrganizationUnitDto> CreateAsync(OrganizationUnitCreateDto input)
        {
            return _organizationUnitAppService.CreateAsync(input);
        }

        [HttpDelete]
        [Route("{id}")]
        public Task DeleteAsync(Guid id)
        {
            return _organizationUnitAppService.DeleteAsync(id);
        }

        [HttpDelete]
        [Route("{id}/members/{memberId}")]
        public Task DeleteMembersAsync(Guid id, Guid memberId)
        {
            return _organizationUnitAppService.DeleteMembersAsync(id, memberId);
        }

        [HttpDelete]
        [Route("{id}/roles/{roleId}")]
        public Task DeleteRolesAsync(Guid id, Guid roleId)
        {
            return _organizationUnitAppService.DeleteRolesAsync(id, roleId);
        }

        [HttpGet]
        [Route("{id}")]
        public Task<OrganizationUnitDto> GetAsync(Guid id)
        {
            return _organizationUnitAppService.GetAsync(id);
        }

        [HttpGet]
        [Route("all")]
        public Task<ListResultDto<OrganizationUnitDto>> GetListAllAsync()
        {
            return _organizationUnitAppService.GetListAllAsync();
        }

        [HttpGet]
        public Task<PagedResultDto<OrganizationUnitDto>> GetListAsync(PagedAndSortedResultRequestDto input)
        {
            return _organizationUnitAppService.GetListAsync(input);
        }

        [HttpGet]
        [Route("{id}/members")]
        public Task<PagedResultDto<IdentityUserDto>> GetMembersAsync(Guid id, GetIdentityUsersInput input)
        {
            return _organizationUnitAppService.GetMembersAsync(id, input);
        }

        [HttpGet]
        [Route("{id}/roles")]
        public Task<PagedResultDto<IdentityRoleDto>> GetRolesAsync(Guid id, PagedAndSortedResultRequestDto input)
        {
            return _organizationUnitAppService.GetRolesAsync(id, input);
        }

        [HttpPut]
        [Route("{id}/move")]
        public Task PutMoveAsync(Guid id, OrganizationUnitMoveInput input)
        {
            return _organizationUnitAppService.PutMoveAsync(id, input);
        }

        [HttpPut]
        [Route("{id}")]
        public Task<OrganizationUnitDto> UpdateAsync(Guid id, OrganizationUnitUpdateDto input)
        {
            return _organizationUnitAppService.UpdateAsync(id, input);
        }

        [HttpPut]
        [Route("{id}/members")]
        public Task UpdateMembersAsync(Guid id, OrganizationUnitUserInput input)
        {
            return _organizationUnitAppService.UpdateMembersAsync(id, input);
        }

        [HttpPut]
        [Route("{id}/roles")]
        public Task UpdateRolesAsync(Guid id, OrganizationUnitRoleInput input)
        {
            return _organizationUnitAppService.UpdateRolesAsync(id, input);
        }
    }
}
